home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / intersectCrvPreset.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  5.1 KB  |  163 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  June 25, 1998
  22. //  Author:        mgr
  23. //
  24. //  Description:
  25. //      The intersectCrvPreset() procedure executes an intersect curve 
  26. //        operation on a pair of curves based on the intersect option vars. 
  27. //        In general if you have n curves selected, (n-1) curve intersect 
  28. //        operations would be carried out: each of the 1..n-1 curves is
  29. //        intersected with the nth curve.
  30. //
  31. //  Input Arguments:
  32. //      None.
  33. //
  34. //  Return Value:
  35. //      None.
  36. //
  37. global proc intersectCrvPreset(
  38. int $history,
  39. float $tol,
  40. int $useDirection,        // 0 - off, 1 - on, 2 - use current view direction
  41.                         // 3 - x axis, 4 - y axis, 5 - z axis
  42.                         // 6 - smart mode: use view vector in ortho view
  43.                         // but NO direction in persp view.
  44. float $dirX,
  45. float $dirY,
  46. float $dirZ,
  47. int $intersectAllCurveOrWithLast )    // 1 - intersect all curves with all curves.
  48.                                 // 2 - intersect all curves with last curve only
  49. //
  50. //  Description:
  51. //         This proc takes the two selected curves and adds a marker 
  52. //        (i.e. locator) on the first curve whenever it intersects the second
  53. //        and selects all the new markers.
  54. //
  55. {
  56.     // Get the list of nurbs curves selected
  57.     //
  58.     global int $gSelectNurbsCurvesBit;
  59.     global int $gSelectCurvesOnSurfacesBit;
  60.     string $curveList[] = `filterExpand -ex true -sm $gSelectNurbsCurvesBit -sm $gSelectCurvesOnSurfacesBit`;
  61.     int $numSelected = size($curveList);
  62.     if ( $numSelected < 2 )
  63.     {
  64.            error "Select at least two NURBS curves to intersect."; 
  65.         return;
  66.     }
  67.  
  68.     // If we're to use the "current view direction", then find out what it is.
  69.     //
  70.     float $dir[3] ;
  71.     $dir[0] = $dirX;
  72.     $dir[1] = $dirY;
  73.     $dir[2] = $dirZ;
  74.     int $useDir = $useDirection;
  75.     if( $useDirection == 2 ) {
  76.         $dir = nurbsViewDirectionVector(0) ;
  77.         $useDir = 1;
  78.     } else if( ($useDirection == 3) || 
  79.                ($useDirection == 4) || 
  80.                ($useDirection == 5)) {
  81.         // Using x axis, or y axis, or z axis.  So set 
  82.         // the $useDir argument
  83.         //
  84.         $useDir = 1;
  85.     } else if( ($useDirection == 6) ) {
  86.         $dir = nurbsViewDirectionVector(0) ;
  87.         $useDir = 2;    
  88.     }
  89.     if( $useDir == 2 ) {
  90.         // If persp view, then $useDir = 0;
  91.         // If ortho view, then $useDir = 1;
  92.         string $currentCamera = `lookThru -q`;
  93.         if( `camera -q -o $currentCamera` )  {
  94.             $useDir = 1;
  95.         } else {
  96.             $useDir = 0;
  97.         }
  98.     }
  99.  
  100.     // Find all intersections with ALL CURVES or with LAST CURVE only
  101.     //
  102.     string $resultLocators[];
  103.     string $parms[];
  104.     string $intersectNodes[];
  105.     if( $intersectAllCurveOrWithLast == 1 )  {
  106.         $parms = findAllIntersections( $curveList, 
  107.                 $numSelected,    // this means all curves
  108.                 $useDir, $dir[0], $dir[1], $dir[2], $tol, 0, // 0 means unsorted
  109.                 $history, $intersectNodes );
  110.     } else {
  111.         $parms = findAllIntersections( $curveList, 
  112.                 1,    // 1 means last curve
  113.                 $useDir, $dir[0], $dir[1], $dir[2], $tol, 0, // 0 means unsorted
  114.                 $history, $intersectNodes );
  115.     }
  116.  
  117.     // For each intersection, create a locator
  118.     //
  119.     int $c, $p;
  120.     int $numParms;
  121.     for( $c = 0; $c < $numSelected; $c ++ ) {
  122.  
  123.         // Parse the parms string into a list of parameter values
  124.         string $tok[];
  125.         float $floatParms[];
  126.         int $numTok = `tokenize $parms[$c] " " $tok`;
  127.         if( $numTok == 0 )  continue; 
  128.         for( $j = 0; $j < $numTok; $j ++ ) {
  129.             if( size($tok[$j]) > 0 ) {
  130.                 $floatParms[$j] = $tok[$j];
  131.             }
  132.         }
  133.         $numParms = size($floatParms);
  134.         if( $numParms == 0 )  continue; 
  135.  
  136.         // Parse out the intersect node string, if there is one
  137.         //
  138.         string $nodes[];
  139.         int $numNodes = `tokenize $intersectNodes[$c] " " $nodes`;
  140.  
  141.         // For each parameter value in $floatParms, create a locator and
  142.         // add it to the resultLocators list
  143.         //
  144.         for( $p = 0; $p < $numParms; $p ++ ) {
  145.             $locator = eval("paramLocator " +  $curveList[$c] + ".u[" 
  146.                                 + $floatParms[$p] + "]");
  147.             $resultLocators[size($resultLocators)] = $locator;
  148.  
  149.             // if history is on then connect the crv/crv intersect node 
  150.             // parameter value to a locator
  151.             //
  152.             if( ($history == 1) && ($numNodes > 0)) {
  153.                 connectAttr $nodes[$p] ($locator + ".localPositionX");
  154.             }
  155.         }
  156.         clear($floatParms);
  157.     }
  158.  
  159.     // Select all the new markers
  160.     //
  161.     if ( size($resultLocators) > 0 ) select -r $resultLocators;
  162. }
  163.